// Template, major revision 3
// IGAD/NHTV - Jacco Bikker - 2006-2009

#include "physics.h"
#include "string.h"
#include "surface.h"
#include "stdlib.h"
#include "template.h"
#include "game.h"
#include "pBody.h"
#include "pPlayer.h"

//Game Logic includes
#include "Includer.h"


using namespace Tmpl8;

extern Surface* surfaceLink;
vector3 campos;
//dynObject* mDObject;//fucking global ff

namespace Tmpl8
{
	struct gamePimpl
	{
		dynObject* mDObject;
		
		gamePimpl();
		~gamePimpl();
	};

	gamePimpl::gamePimpl()
	{
	}
	gamePimpl::~gamePimpl()
	{
	}
}

Game::Game()
: mPimpl(*new gamePimpl() )
{
}

void Game::Init()
{
	mPhysics = new Physics();
	campos = vector3(0, 0, 0);
	mPhysics->SetPointerToCam(&campos);
	surfaceLink = m_Screen;
	// put your initialization code here; will be executed once
		

	pBody* OutLines = mPhysics->CreateBody(vector3(), 0, PMODE_STATIC);
	OutLines->AddLine(vector3(), vector3(SCRWIDTH, 0,0), mPhysics->GetMaterial("default"));
	OutLines->AddLine(vector3(), vector3(0, SCRHEIGHT,0), mPhysics->GetMaterial("default"));
	OutLines->AddLine(vector3(SCRWIDTH, 0, 0), vector3(SCRWIDTH, SCRHEIGHT,0), mPhysics->GetMaterial("default"));
	OutLines->AddLine(vector3(0 , SCRHEIGHT,0), vector3(SCRWIDTH, SCRHEIGHT,0), mPhysics->GetMaterial("default"));


	OutLines->AddLine(vector3(0 , SCRHEIGHT / 1.3,0), vector3(60, SCRHEIGHT / 1.2,0), mPhysics->GetMaterial("default"));
	OutLines->AddLine(vector3(300 , 300,0), vector3(600, 200,0), mPhysics->GetMaterial("default"));
	OutLines->AddLine(vector3(80 , 120,0), vector3(250, 250,0), mPhysics->GetMaterial("default"));


	mPlayer = mPhysics->CreatePlayer(vector3(20,20,0));
	
	//recent
	mPhysics->CreateBody(vector3(SCRWIDTH /4, SCRHEIGHT/4, 0), 0, PMODE_DYNAMIC)->AddBox(vector3(), vector3(10, 20, 0), PI/3, mPhysics->GetMaterial("default"), 10);
		
	//AddCircle(vector3(0,0,0), 50, mPhysics->GetMaterial("default"), 10);
	
	mBody = mPhysics->CreateBody(vector3(0,0,0),20, PMODE_DYNAMIC);
	mBody->AddCircle(vector3(0,0,0), 20, mPhysics->GetMaterial("default"), 10);
	mPimpl.mDObject = new dynObject(mBody);
	//mDObject = new dynObject(mBody);
	
	
	//rotating sprite
	RotationTest = new Surface("assets/mill.tga");
	RotationSprite =  new Sprite(RotationTest, 16);
	
}

static float temp = 0; //hmmm 

void Game::Tick( float a_DT )
{
	// render a single frame here
	m_Screen->Clear( 0 );
	m_Screen->Print( "hello world", 2, 2, 0xffffff );
	m_Screen->Line( 2, 9, 66, 9, 0xffffff );
	
	//debug rotation
	temp+=(a_DT / 100);
	
	RotationSprite->DrawRotated(100,100,temp*0.01f,m_Screen);
	RotationSprite->SetFrame( ((int)temp) % 16);
	/// end debug ///
	
	mPhysics->Tick();
	mPhysics->Render();
}


void Game::KeyDown( unsigned int code )
{
	//mPlayer->KeyDown(code);

}

void Game::KeyUp( unsigned int code ) 
{
	//mPlayer->KeyUp(code);

}

void Game::MouseMove( unsigned int x, unsigned int y ) 
{
	//mPlayer->SetMousePos();
}

void Game::MouseUp( unsigned int button ) 
{

}

void Game::MouseDown( unsigned int button ) 
{

}

